package com.xipu.yygh.hosp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xipu.yygh.common.exception.YyghException;
import com.xipu.yygh.hosp.mapper.HospitalSetMapper;
import com.xipu.yygh.hosp.service.HospitalSetService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xipu.yygh.model.hosp.HospitalSet;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 医院设置表 服务实现类
 * </p>
 *
 * @author gql
 * @since 2022-04-17
 */
@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet>
        implements HospitalSetService {

    /**
     * 根据医院编码查询医院SignKey
     * @param hoscode 医院编码
     * @return SignKey
     */
    @Override
    public String getSignKey(String hoscode) {
        LambdaQueryWrapper<HospitalSet> eq
                = Wrappers.lambdaQuery(HospitalSet.class).eq(HospitalSet::getHoscode, hoscode);
        HospitalSet hospitalSet = this.baseMapper.selectOne(eq);
        if (StringUtils.isEmpty(hospitalSet)) {
            throw new YyghException(20001, "医院信息不存在");
        } else {
            return hospitalSet.getSignKey();
        }
    }
}
